/**
 * 
 * Code contributed by IUP Research Institute
 *
 *     Code contributed by IUP Research Institute
 *     This file is part of NetworkMon.
 *
 *   NetworkMon is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; version 2 of the License.
 *
 *   NetworkMon is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with NetworkMon; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
package networkbackend;

import net.sourceforge.jpcap.net.ARPPacket;
import net.sourceforge.jpcap.net.EthernetPacket;
import net.sourceforge.jpcap.net.ICMPPacket;
import net.sourceforge.jpcap.net.IGMPPacket;
import net.sourceforge.jpcap.net.IPPacket;
import net.sourceforge.jpcap.net.Packet;
import net.sourceforge.jpcap.net.TCPPacket;
import net.sourceforge.jpcap.net.UDPPacket;

// enum PacketType {ARP, Ethernet, ICMP, IGMP, IP, TCP, UDP, Unknown};
/**
 * 
 * @author Brian Slocum
 */
public class APacket {

	private String sendersIPAddress;
	private int sendersportNumber;
	private String receiversIPAddress;
	private int receiversportNumber;
	private int packetSize = 0;
	private int protoCall = 0;
	private String receiversName;
	private String sendersName;

	/** Creates a new instance of APacket */
	public APacket(Packet thePacket) {

		packetSize = thePacket.getData().length + thePacket.getHeader().length;

		if (thePacket instanceof ARPPacket) {
			ARPPacket temp = (ARPPacket) thePacket;
			receiversIPAddress = temp.getDestinationProtoAddress();
			sendersIPAddress = temp.getSourceProtoAddress();
			receiversportNumber = 0;
			sendersportNumber = 0;
			protoCall = temp.getProtocol();
		}

		if (thePacket instanceof EthernetPacket) {
			EthernetPacket temp = (EthernetPacket) thePacket;
			receiversIPAddress = temp.getDestinationHwAddress();
			sendersIPAddress = temp.getSourceHwAddress();
			protoCall = temp.getEthernetProtocol();
			receiversportNumber = 0;
			sendersportNumber = 0;
			protoCall = temp.getProtocol();
		}

		if (thePacket instanceof ICMPPacket) {
			ICMPPacket temp = (ICMPPacket) thePacket;
			receiversIPAddress = temp.getDestinationAddress();
			sendersIPAddress = temp.getSourceAddress();
			receiversportNumber = 0;
			sendersportNumber = 0;
			protoCall = temp.getProtocol();
		}

		if (thePacket instanceof IGMPPacket) {
			IGMPPacket temp = (IGMPPacket) thePacket;
			receiversIPAddress = temp.getDestinationAddress();
			sendersIPAddress = temp.getSourceAddress();
			receiversportNumber = 0;
			sendersportNumber = 0;
			protoCall = temp.getProtocol();
		}

		if (thePacket instanceof IPPacket) {
			IPPacket temp = (IPPacket) thePacket;
			receiversIPAddress = temp.getDestinationAddress();
			sendersIPAddress = temp.getSourceAddress();
			receiversportNumber = 0;
			sendersportNumber = 0;
			protoCall = temp.getProtocol();
		}

		if (thePacket instanceof TCPPacket) {
			TCPPacket temp = (TCPPacket) thePacket;

			receiversIPAddress = temp.getDestinationAddress();
			sendersIPAddress = temp.getSourceAddress();
			receiversportNumber = temp.getDestinationPort();
			sendersportNumber = temp.getSourcePort();
			protoCall = temp.getProtocol();
		}

		if (thePacket instanceof UDPPacket) {
			UDPPacket temp = (UDPPacket) thePacket;
			receiversIPAddress = temp.getDestinationAddress();
			sendersIPAddress = temp.getSourceAddress();
			receiversportNumber = temp.getDestinationPort();
			sendersportNumber = temp.getSourcePort();
			protoCall = temp.getProtocol();
		}
	}

	public String getSourceIPAddress() {
		return sendersIPAddress;
	}

	public int getSourcePortNumber() {
		return sendersportNumber;
	}

	public String getDestinationIPAddress() {
		return receiversIPAddress;
	}

	public int getDestinationPortNumber() {
		return receiversportNumber;
	}

	public int getTheSize() {
		return packetSize;
	}

	public int getProtocall() {
		return protoCall;
	}

	public String getReceiversName() {
		return receiversName;
	}

	public String getSendersName() {
		return sendersName;
	}

	public void setReceiversName(String name) {
		receiversName = name;
	}

	public void setSendersName(String name) {
		sendersName = name;
	}

}
